﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class Group_userDAO:IData<Group_user> 
 	{
		public Group_userDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref Group_user item, int t) {
			 SqlParameter p = new SqlParameter(); 
			 if( t == 0)
				p.Direction = ParameterDirection.Output;
			 p.ParameterName = "@" + Group_user.c_id;
			 p.Value = item.id;
			 Object obj = item.id; 
			int i = connec.ExecuteNonQuery("sp_Group_user", CommandType.StoredProcedure,p,ref obj,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Group_user.c_group_name, item.group_name), new SqlParameter("@" + Group_user.c_note, item.note),
				 new SqlParameter("@" + Group_user.c_stt, item.stt));
			if(t == 0)
				item.id = Convert.ToInt64(obj);
			return i;
		}

		public override Group_user GetItem(IDataReader dr)
		{
			Group_user obj = new Group_user();
			obj.id = Convert.ToInt64(dr[Group_user.c_id]);
			obj.group_name = Convert.ToString(dr[Group_user.c_group_name]);
			obj.note = Convert.ToString(dr[Group_user.c_note]);
			obj.stt = Convert.ToInt32(dr[Group_user.c_stt]);
			return obj;
		}

		public override List<Group_user> GetAll()
		{
			return GetAll("sp_GetAllGroup_user", CommandType.StoredProcedure);
		}

		public override Group_user GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.id == Convert.ToInt64(id));
		}
		public override Group_user GetItemById(Group_user item){
			throw new NotImplementedException();
		}

	}

 }
